﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using Cat.Domain.Repositories;
using Cat.Domain.Entities;

namespace Cat.Web.Controllers
{
    public class HomeController : Controller
    {
        private ILinkRepository _repository;
        //
        // GET: /Home/
        public HomeController(ILinkRepository repository) {
            _repository = repository;
        }

        public ViewResult Index()
        {
            //var links = _repository.GetLinksByArea("a");
            LinkRepository links1 = new LinkRepository();
            var links = links1.GetLinks();

            //ViewBag.links_a1 = links.Where(i=>i.Area=="a1").OrderByDescending(i=>i.SortOrder);
            //ViewBag.links_a2 = links.Where(i => i.Area == "a2");
            //ViewBag.links_a3 = links.Where(i => i.Area == "a3");

            //ViewBag.links_b = links.Where(i => i.Area == "b");

            //ViewBag.links_c = links.Where(i => i.Area == "c");
            //ViewBag.links_d = links.Where(i => i.Area == "d");
            //ViewBag.links_d1 = links.Where(i => i.Area == "d1");
            //ViewBag.links_d2 = links.Where(i => i.Area == "d2");

            //ViewBag.links_e = links.Where(i => i.Area == "e");
            //ViewBag.links_e1 = links.Where(i => i.Area == "e1");
            //ViewBag.links_e2 = links.Where(i => i.Area == "e2");

            //ViewBag.links_f = links.Where(i => i.Area == "f");
            //ViewBag.links_g = links.Where(i => i.Area == "g");
            //ViewBag.links_h = links.Where(i => i.Area == "h");
            //ViewBag.links_i = links.Where(i => i.Area == "i");

            var links_j = links.Where(i => i.Area == "j").ToArray();

            string[] linkstr = new string[links_j.Length];
            for (int i = 0; i < links_j.Length; i++)
            {
                linkstr[i] = "<a href=\"" + links_j[i].NavigateUrl + "\">" + links_j[i].Text + "</a>";
            }

            ViewBag.str = string.Join(" | ", linkstr);

            return View(links);
          
        }

    }
}
